package com.smart.controller;

import com.smart.pojo.ResultBean;
import com.smart.pojo.TaskForm;
import com.smart.pojo.TaskInfo;
import com.smart.service.IProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("process")
public class ProcessController {

    @Autowired
    private IProcessService processService;


    /**
     * 根据用户ID查询待办事务
     * @param userId
     * @return
     */
    @GetMapping("queryTaskByUserId/{userId}")
    public ResultBean queryTaskByUserId(@PathVariable("userId") Long userId) {
        List<TaskInfo> taskInfos = processService.queryTaskByUserId(userId);
        return ResultBean.success(taskInfos);
    }

    /**
     * 根据taskId获取task任务相关的表单信息，包括当前任务可执行的命令、关联的表单数据以及关联的批注列表
     * @param taskId
     * @return
     */
    @GetMapping("/viewTaskForm/{taskId}")
    public ResultBean viewTaskForm(@PathVariable("taskId") String taskId) {
        System.out.println("请求的taskID：" + taskId);
        TaskForm taskForm = processService.viewTaskForm(taskId);
        return ResultBean.success(taskForm);
    }

    /**
     * 根据审批类型和申请单ID获取申请流程的详细信息
     * @param billType
     * @param id
     * @return
     */
    @GetMapping("auditTrail/{billType}/{id}")
    public ResultBean auditTrail(@PathVariable("billType") String billType,@PathVariable("id") Long id){
        System.out.println("申请类型：" + billType + ",ID：" + id);
        TaskForm taskForm = processService.auditTrail(billType,id);
        return ResultBean.success(taskForm);
    }

    @GetMapping("deleteByTaskId/{taskId}")
    public ResultBean deleteByTaskId(@PathVariable("taskId") String taskId){
        System.out.println("要删除的流程的Id：" + taskId);
        boolean rs = processService.deleteByTaskId(taskId);
        return rs ? ResultBean.success() : ResultBean.error();
    }

}
